package com.pzhu.dormitory.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pzhu.dormitory.dao.CampusDao;
import com.pzhu.dormitory.entity.BuildingEntity;
import com.pzhu.dormitory.entity.CampusEntity;
import com.pzhu.dormitory.service.CampusService;
import com.pzhu.dormitory.utils.PageUtils;
import com.pzhu.dormitory.utils.Query;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("campusService")
public class CampusServiceImpl extends ServiceImpl<CampusDao, CampusEntity> implements CampusService {

    @Override
    public PageUtils<CampusEntity> queryPage(Map<String, Object> params) {
        QueryWrapper<CampusEntity> queryWrapper = new QueryWrapper<>();
        String name = (String) params.get("name");
        if (StringUtils.isNotBlank(name)) {
            queryWrapper.lambda().like(CampusEntity::getName, "%" + name + "%");
        }
        IPage<CampusEntity> page = this.page(
                new Query<CampusEntity>().getPage(params),
                queryWrapper
        );
        return new PageUtils<>(page);
    }

}
